

cap program drop PlotCoeff_qtrs
program define PlotCoeff_qtrs
syntax, NAME(string) XLINE(real) [TITLE(string)] [YTI(string)] [XTI(string)]  [YLABEL(string)] [XLABEL(string)] VRS(string)

	mat b = e(b)
	mat s = e(V)

	foreach vr in `: colnames b' {
		
		local iter = `iter'+1
		
		mat x = b[1,"`vr'"]
		local beta = x[1,1]

		mat y = s[`iter',"`vr'"]
		local se = sqrt(y[1,1])

		local obs`iter' "`: colnames x'|`beta'|`se'"

		macro drop _beta _se
		mat drop x y
	}
	
	preserve

		clear
		qui set obs `iter'
		qui gen ind=""
		forval vl = 1/`iter' {
			qui replace ind="`obs`vl''" in `vl'
			macro drop _obs`vl'
		}
		macro drop _iter
		
		qui split ind, parse("|")
		qui keep if regexm(ind1,"`vrs'")==1
		
		qui gen beta=ind2
		qui gen se=ind3
		
		qui split ind1, parse("_") 
		replace ind12=subinstr(ind12,"q","-",.)
		qui destring ind12, replace
		confirm numeric var ind12
		qui gen etime=ind12

		keep beta se etime

		qui destring _all, replace
		confirm numeric var etime beta se						
		gen ind=1
		qui tsset ind etime
		tsfill
		qui replace beta=0 if beta==.
		drop ind
				
		qui gen low=beta-(1.96*se)
		qui gen hi=beta+(1.96*se)
		
		*format date %tq
		
		if "`ylabel'"!="" local ylabel `"ylabel(`ylabel')"'
		if "`xlabel'"!="" local xlabel `"xlabel(`xlabel')"'
		if "`title'"!=""  local title  "`title'"
		
		if "`yti'"!=""   local yti `"`yti'"'
					else local yti "Estimated effect on log hourly wages"
		if "`xti'"!=""   local xti `"`xti'"'
					else local xti "Event time in quarters"

		#d 
			twoway rcap hi low etime || connected beta etime,
			
			yline(0, lcolor(black) lw(vthin))
			xline(`xline', lcolor(red) lw(vthin)) 
			
			`ylabel' `xlabel' 
			
			title("`title'")
			xti("`xti'") 
			yti("`yti'", margin(0 4 0 0))
			
			ylabel(, glc(gs14) glw(vthin))
			
			legend(off) name(`name', replace)
			
			graphregion(color(white) margin(small))
		;
		#d cr
		
	restore

	mat drop b s
	
end

